package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id = #{id}")
    // 根据分类id查询菜品
    int selectByCategoryId(Long id);

    // 新增菜品
    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user) " +
            "values(#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Dish dish);

    // 条件分页查询菜品
    Page<DishVO> queryPageOnConditional(DishPageQueryDTO dishPageQueryDTO);

    //根据id查询菜品及口味
    DishVO getByIdWithFlavor(Long id);

    // 修改菜品
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    //批量查询菜品
    List<Dish> getBatchByIds(List<Long> ids);

    // 批量删除菜品
    void deleteBatchByIds(List<Long> ids);

    //根据分类id查询菜品
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user " +
            "from dish where category_id = #{categoryId}")
    List<Dish> getDishByCategoryId(Long categoryId);
}
